package com.dm.cloud.auth.controller.defalut;

import com.dm.cloud.core.mode.ResultModel;
import com.dm.cloud.oauthlib.service.anon.HasLogin;
import com.dm.cloud.tkmybatis.service.BaseEntityService;
import com.dm.cloud.tkmybatis.service.EntityBaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.dm.cloud.auth.common.po.AuthRole;
import com.dm.cloud.auth.common.dto.AuthRoleDTO;
import com.dm.cloud.auth.common.request.AuthRoleSearchRequest;
import com.dm.cloud.auth.service.AuthRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
   * @author hcx
   * @type AuthRoleController.java
   * @desc 角色表 AuthRole controller
   */
@RestController
@RequestMapping("/apis/v1/authRole")
@Tag(name =  "角色表  AuthRolecontroller")
@HasLogin
public class AuthRoleController extends EntityBaseController<AuthRoleSearchRequest, AuthRole, AuthRoleDTO> {

    @Autowired
    private AuthRoleService authRoleService;
    @Override
    public AuthRole getEntity() {
        return new AuthRole();
    }

    @Override
    public AuthRoleDTO getDTO() {
        return new AuthRoleDTO();
    }
    @Override
    public BaseEntityService<AuthRoleSearchRequest, AuthRole> getService() {
        return authRoleService;
    }

    @GetMapping("findByUsername")
    @Operation(summary = "根据用户名查询角色列表")
    public ResultModel<List<AuthRoleDTO>> findByName(@Parameter(name = "username", in = ParameterIn.QUERY, description = "用户名",
            required = true) String username){
        return ResultModel.success(authRoleService.findRoleByUsername(username));
    }



}
